package HLUserControl.HLHomepage.HLPageMain;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLImage;
import HLLib.base.HLString;
import HLLib.control.HLPanel;
import HLLib.control.HLPhotoFrame;
import HLLib.control.HLTextPage;
import HLLib.handfere.HLUIRes;
import HLLib.handfere.HLUser;
import HLSubScreen.HLSubScreenManager;

public class HLSelfInfoPanel extends HLPanel {
    public static final int PHOTO_BORDER = 4;

    public static final int PHOTO_TO_TEXT = 8;

    HLUser user;

    HLTextPage mood;

    HLPhotoFrame photo;

    Image sex[] = HLUIRes.uires.GetSex();

    Image goldIcon[];

    public HLSelfInfoPanel(HLUser user) {
        this.user = user;
        goldIcon = HLUIRes.uires.GetGold();

        this.width = (short) HLLib.base.HLScreen.width;

        photo = new HLPhotoFrame(user.head);
        Add(photo);

        height = Math.max(photo.GetHeight() + PHOTO_BORDER * 2, HLGraphics.StringHeight() * 2 + 2 + Math.max(sex[0].getHeight(), HLGraphics.StringHeight() + 1));

        photo.AjustPos(PHOTO_BORDER, 0, 0, height, LEFT_VCENTER);

        tabelStop = true;
    }

    public void Logic() {
        super.Logic();
        if (IsFocus()) {
            RefreshEvent(GetScreenX(), GetScreenY(), GAME_BUTTON_ACTION);
        }
    }

    public void Refresh() {
        super.Refresh();
    }

    public void Render(HLGraphics g) {
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        // g.DrawImageFillRect( backImg[IsFocus()?0:1], screenX, screenY, width,
        // height, TRANS_NONE);
        int topColor = 0xffffffff;// 0xffe6e6e8;
        if (IsFocus()) {
            topColor = 0xff4f77cb;
        }
        g.FillRect(screenX, screenY, width, height, topColor);

        super.Render(g);

        int stringColor = 0xff646567;
        int nameColor = 0;
        if (IsFocus()) {
            stringColor = 0xfffffe;
            nameColor = 0xfffffe;
        } else {
        }
        int offsetX = screenX + user.head.GetWidth() + PHOTO_BORDER + PHOTO_TO_TEXT;
        int offsetY = screenY;
        offsetY = screenY + 1;
        g.DrawImage(new HLImage(user.sex == 1 ? sex[0] : sex[1]), offsetX, offsetY, TRANS_NONE);

        g.DrawString(new HLString(user.nickName), offsetX + sex[0].getWidth() + 4, offsetY, nameColor, 0, TEXT_STYLE_NORMAL);
        offsetY += Math.max(sex[0].getHeight(), HLGraphics.StringHeight());

        g.DrawString(new HLString(user.resideAddress.toString()), offsetX, offsetY, stringColor, 0, TEXT_STYLE_NORMAL);

        offsetY += HLGraphics.StringHeight();
        g.DrawImage(new HLImage(goldIcon[0]), offsetX, offsetY, TRANS_NONE);
        offsetX += goldIcon[0].getWidth() + 2;
        g.DrawString(new HLString(user.credit + ""), offsetX, offsetY, nameColor, 0, TEXT_STYLE_NORMAL);
        offsetX += 60;
        if (HLSubScreenManager.isOwen(user)) {
            g.DrawImage(new HLImage(goldIcon[1]), offsetX, offsetY, TRANS_NONE);
            offsetX += goldIcon[0].getWidth() + 2;
            g.DrawString(new HLString(user.gold + ""), offsetX, offsetY, nameColor, 0, TEXT_STYLE_NORMAL);
        }
    }

}
